#include <benchmark/benchmark.h>

#include <memory>
#include <random>
#include <string>

#include "data_dumper.h"

static void BM_DataDumperReport_Buffer(benchmark::State& state) {
  uint32_t ring_buffer_size = state.range(0);
  uint32_t report_count = state.range(1);

  // 为每个测试用例创建唯一的路径
  std::string test_path = "./tmp/benchmark_test_" +
                          std::to_string(ring_buffer_size) + "_" +
                          std::to_string(report_count);

  DataDumper::GetInstance().Init(test_path, ring_buffer_size);
  DataDumper::GetInstance().Start();

  for (auto _ : state) {
    state.PauseTiming();  // 暂停计时器
    std::vector<std::unique_ptr<MindSporeOpRangeData>> data_vec;
    for (uint32_t i = 0; i < report_count; ++i) {
      data_vec.push_back(std::make_unique<MindSporeOpRangeData>(
        0, // device_id
        0, // tag
        1, // thread_id
        2, // flow_id
        3, // step
        4, // start_time_ns
        5, // end_time_ns
        6, // process_id
        7, // module_index
        8, // event_index
        9, // stage_index
        10, // level
        true, // is_async
        true, // is_graph_data
        true // is_stage
    ));
    }
    state.ResumeTiming();  // 恢复计时器

    for (auto& report_data : data_vec) {
      DataDumper::GetInstance().Report(std::move(report_data));
    }
  }

  DataDumper::GetInstance().Stop();
}

// BENCHMARK(BM_DataDumperReport_Buffer)
//     ->Ranges({{1024, 10 * 1024}, {10000, 100000}})
//     ->Unit(benchmark::kMicrosecond);

BENCHMARK(BM_DataDumperReport_Buffer)
    ->Args({10 * 1024, 100000})
    ->Unit(benchmark::kMicrosecond);

BENCHMARK_MAIN();
